#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve()
{
    int n, s;
    int ans = 0;
    cin >> n >> s;
    int dxi, dyi, xi, yi;
    for(int i = 0;i < n;i ++)
    {
        cin >> dxi >> dyi >> xi >> yi;
        if(dxi == dyi) ans += (xi == yi);
        else ans += (xi + yi == s);
    }
    cout << ans << endl;
    ans = 0;
}
signed main()
{
    int t; cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}